home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_apache.idb / usr / freeware / catman / u_man / cat7 / regex.Z / regex
Encoding:
Text File  |  1999-07-16  |  11.4 KB  |  265 lines

  1.  
  2.  
  3.  
  4.      RRRREEEEGGGGEEEEXXXX((((7777))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((7777 FFFFeeeebbbb 1111999999994444))))          RRRREEEEGGGGEEEEXXXX((((7777))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       regex    - POSIX    1003.2 regular expressions
  10.  
  11.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  12.       Regular expressions (``RE''s), as defined in POSIX 1003.2,
  13.       come in two forms:  modern REs (roughly those    of _e_g_r_e_p;
  14.       1003.2 calls these ``extended'' REs) and obsolete REs
  15.       (roughly those of _e_d;    1003.2 ``basic'' REs).    Obsolete REs
  16.       mostly exist for backward compatibility in some old
  17.       programs; they will be discussed at the end.    1003.2 leaves
  18.       some aspects of RE syntax and    semantics open;    `|-' marks
  19.       decisions on these aspects that may not be fully portable to
  20.       other    1003.2 implementations.
  21.  
  22.       A (modern) RE    is one|-    or more    non-empty|- _b_r_a_n_c_h_e_s, separated
  23.       by `|'.  It matches anything that matches one    of the
  24.       branches.
  25.  
  26.       A branch is one|- or more _p_i_e_c_e_s, concatenated.  It matches a
  27.       match    for the    first, followed    by a match for the second,
  28.       etc.
  29.  
  30.       A piece is an    _a_t_o_m possibly followed by a single|- `*', `+',
  31.       `?', or _b_o_u_n_d.  An atom followed by `*' matches a sequence
  32.       of 0 or more matches of the atom.  An    atom followed by `+'
  33.       matches a sequence of    1 or more matches of the atom.    An
  34.       atom followed    by `?' matches a sequence of 0 or 1 matches of
  35.       the atom.
  36.  
  37.       A _b_o_u_n_d is `{' followed by an    unsigned decimal integer,
  38.       possibly followed by `,' possibly followed by    another
  39.       unsigned decimal integer, always followed by `}'.  The
  40.       integers must    lie between 0 and RE_DUP_MAX (255|-) inclusive,
  41.       and if there are two of them,    the first may not exceed the
  42.       second.  An atom followed by a bound containing one integer
  43.       _i and    no comma matches a sequence of exactly _i matches of
  44.       the atom.  An    atom followed by a bound containing one
  45.       integer _i and    a comma    matches    a sequence of _i    or more
  46.       matches of the atom.    An atom    followed by a bound containing
  47.       two integers _i and _j matches a sequence of _i through _j
  48.       (inclusive) matches of the atom.
  49.  
  50.       An atom is a regular expression enclosed in `()' (matching a
  51.       match    for the    regular    expression), an    empty set of `()'
  52.       (matching the    null string)|-, a _b_r_a_c_k_e_t _e_x_p_r_e_s_s_i_o_n (see
  53.       below), `.'  (matching any single character),    `^' (matching
  54.       the null string at the beginning of a    line), `$' (matching
  55.       the null string at the end of    a line), a `\' followed    by one
  56.       of the characters `^.[$()|*+?{\' (matching that character
  57.       taken    as an ordinary character), a `\' followed by any other
  58.       character|- (matching that character taken as an ordinary
  59.       character, as    if the `\' had not been    present|-), or a    single
  60.  
  61.  
  62.  
  63.      Page 1                          (printed 5/3/99)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      RRRREEEEGGGGEEEEXXXX((((7777))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((7777 FFFFeeeebbbb 1111999999994444))))          RRRREEEEGGGGEEEEXXXX((((7777))))
  71.  
  72.  
  73.  
  74.       character with no other significance (matching that
  75.       character).  A `{' followed by a character other than    a
  76.       digit    is an ordinary character, not the beginning of a
  77.       bound|-.  It is illegal to end    an RE with `\'.
  78.  
  79.       A _b_r_a_c_k_e_t _e_x_p_r_e_s_s_i_o_n is a list of characters enclosed    in
  80.       `[]'.     It normally matches any single    character from the
  81.       list (but see    below).     If the    list begins with `^', it
  82.       matches any single character (but see    below) _n_o_t from    the
  83.       rest of the list.  If    two characters in the list are
  84.       separated by `-', this is shorthand for the full _r_a_n_g_e of
  85.       characters between those two (inclusive) in the collating
  86.       sequence, e.g. `[0-9]' in ASCII matches any decimal digit.
  87.       It is    illegal|- for two ranges    to share an endpoint, e.g.
  88.       `a-c-e'.  Ranges are very collating-sequence-dependent, and
  89.       portable programs should avoid relying on them.
  90.  
  91.       To include a literal `]' in the list,    make it    the first
  92.       character (following a possible `^').     To include a literal
  93.       `-', make it the first or last character, or the second
  94.       endpoint of a    range.    To use a literal `-' as    the first
  95.       endpoint of a    range, enclose it in `[.' and `.]' to make it
  96.       a collating element (see below).  With the exception of
  97.       these    and some combinations using `['    (see next paragraphs),
  98.       all other special characters,    including `\', lose their
  99.       special significance within a    bracket    expression.
  100.  
  101.       Within a bracket expression, a collating element (a
  102.       character, a multi-character sequence    that collates as if it
  103.       were a single    character, or a    collating-sequence name    for
  104.       either) enclosed in `[.' and `.]' stands for the sequence of
  105.       characters of    that collating element.     The sequence is a
  106.       single element of the    bracket    expression's list.  A bracket
  107.       expression containing    a multi-character collating element
  108.       can thus match more than one character, e.g. if the
  109.       collating sequence includes a    `ch' collating element,    then
  110.       the RE `[[.ch.]]*c' matches the first    five characters    of
  111.       `chchcc'.
  112.  
  113.       Within a bracket expression, a collating element enclosed in
  114.       `[=' and `=]'    is an equivalence class, standing for the
  115.       sequences of characters of all collating elements equivalent
  116.       to that one, including itself.  (If there are    no other
  117.       equivalent collating elements, the treatment is as if    the
  118.       enclosing delimiters were `[.' and `.]'.)  For example, if o
  119.       and o^    are the    members    of an equivalence class, then
  120.       `[[=o=]]', `[[=o^=]]',    and `[oo^]' are all synonymous.    An
  121.       equivalence class may    not|- be    an endpoint of a range.
  122.  
  123.       Within a bracket expression, the name    of a _c_h_a_r_a_c_t_e_r _c_l_a_s_s
  124.       enclosed in `[:' and `:]' stands for the list    of all
  125.       characters belonging to that class.  Standard    character
  126.  
  127.  
  128.  
  129.      Page 2                          (printed 5/3/99)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      RRRREEEEGGGGEEEEXXXX((((7777))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((7777 FFFFeeeebbbb 1111999999994444))))          RRRREEEEGGGGEEEEXXXX((((7777))))
  137.  
  138.  
  139.  
  140.       class    names are:
  141.  
  142.            alnum       digit       punct
  143.            alpha       graph       space
  144.            blank       lower       upper
  145.            cntrl       print       xdigit
  146.  
  147.       These    stand for the character    classes    defined    in _c_t_y_p_e(3).
  148.       A locale may provide others.    A character class may not be
  149.       used as an endpoint of a range.
  150.  
  151.       There    are two    special    cases|- of bracket expressions:    the
  152.       bracket expressions `[[:<:]]'    and `[[:>:]]' match the    null
  153.       string at the    beginning and end of a word respectively.  A
  154.       word is defined as a sequence    of word    characters which is
  155.       neither preceded nor followed    by word    characters.  A word
  156.       character is an _a_l_n_u_m    character (as defined by _c_t_y_p_e(3)) or
  157.       an underscore.  This is an extension,    compatible with    but
  158.       not specified    by POSIX 1003.2, and should be used with
  159.       caution in software intended to be portable to other
  160.       systems.
  161.  
  162.       In the event that an RE could    match more than    one substring
  163.       of a given string, the RE matches the    one starting earliest
  164.       in the string.  If the RE could match    more than one
  165.       substring starting at    that point, it matches the longest.
  166.       Subexpressions also match the    longest    possible substrings,
  167.       subject to the constraint that the whole match be as long as
  168.       possible, with subexpressions    starting earlier in the    RE
  169.       taking priority over ones starting later.  Note that
  170.       higher-level subexpressions thus take    priority over their
  171.       lower-level component    subexpressions.
  172.  
  173.       Match    lengths    are measured in    characters, not    collating
  174.       elements.  A null string is considered longer    than no    match
  175.       at all.  For example,    `bb*' matches the three    middle
  176.       characters of    `abbbc', `(wee|week)(knights|nights)' matches
  177.       all ten characters of    `weeknights', when `(.*).*' is matched
  178.       against `abc'    the parenthesized subexpression    matches    all
  179.       three    characters, and    when `(a*)*' is    matched    against    `bc'
  180.       both the whole RE and    the parenthesized subexpression    match
  181.       the null string.
  182.  
  183.       If case-independent matching is specified, the effect    is
  184.       much as if all case distinctions had vanished    from the
  185.       alphabet.  When an alphabetic    that exists in multiple    cases
  186.       appears as an    ordinary character outside a bracket
  187.       expression, it is effectively    transformed into a bracket
  188.       expression containing    both cases, e.g. `x' becomes `[xX]'.
  189.       When it appears inside a bracket expression, all case
  190.       counterparts of it are added to the bracket expression, so
  191.       that (e.g.) `[x]' becomes `[xX]' and `[^x]' becomes `[^xX]'.
  192.  
  193.  
  194.  
  195.      Page 3                          (printed 5/3/99)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      RRRREEEEGGGGEEEEXXXX((((7777))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((7777 FFFFeeeebbbb 1111999999994444))))          RRRREEEEGGGGEEEEXXXX((((7777))))
  203.  
  204.  
  205.  
  206.       No particular    limit is imposed on the    length of REs|-.
  207.       Programs intended to be portable should not employ REs
  208.       longer than 256 bytes, as an implementation can refuse to
  209.       accept such REs and remain POSIX-compliant.
  210.  
  211.       Obsolete (``basic'') regular expressions differ in several
  212.       respects.  `|', `+', and `?' are ordinary characters and
  213.       there    is no equivalent for their functionality.  The
  214.       delimiters for bounds    are `\{' and `\}', with    `{' and    `}' by
  215.       themselves ordinary characters.  The parentheses for nested
  216.       subexpressions are `\(' and `\)', with `(' and `)' by
  217.       themselves ordinary characters.  `^' is an ordinary
  218.       character except at the beginning of the RE or|- the
  219.       beginning of a parenthesized subexpression, `$' is an
  220.       ordinary character except at the end of the RE or|- the end
  221.       of a parenthesized subexpression, and    `*' is an ordinary
  222.       character if it appears at the beginning of the RE or    the
  223.       beginning of a parenthesized subexpression (after a possible
  224.       leading `^').     Finally, there    is one new type    of atom, a
  225.       _b_a_c_k _r_e_f_e_r_e_n_c_e:  `\' followed    by a non-zero decimal digit _d
  226.       matches the same sequence of characters matched by the _dth
  227.       parenthesized    subexpression (numbering subexpressions    by the
  228.       positions of their opening parentheses, left to right), so
  229.       that (e.g.) `\([bc]\)\1' matches `bb'    or `cc'    but not    `bc'.
  230.  
  231.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  232.       regex(3)
  233.  
  234.       POSIX    1003.2,    section    2.8 (Regular Expression    Notation).
  235.  
  236.      BBBBUUUUGGGGSSSS
  237.       Having two kinds of REs is a botch.
  238.  
  239.       The current 1003.2 spec says that `)'    is an ordinary
  240.       character in the absence of an unmatched `(';    this was an
  241.       unintentional    result of a wording error, and change is
  242.       likely.  Avoid relying on it.
  243.  
  244.       Back references are a    dreadful botch,    posing major problems
  245.       for efficient    implementations.  They are also    somewhat
  246.       vaguely defined (does    `a\(\(b\)*\2\)*d' match    `abbbd'?).
  247.       Avoid    using them.
  248.  
  249.       1003.2's specification of case-independent matching is
  250.       vague.  The ``one case implies all cases'' definition    given
  251.       above    is current consensus among implementors    as to the
  252.       right    interpretation.
  253.  
  254.       The syntax for word boundaries is incredibly ugly.
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                          (printed 5/3/99)
  262.  
  263.  
  264.  
  265.